home *** CD-ROM | disk | FTP | other *** search
- #!/bin/sh
-
- # AUTHOR: Timothy J. Luoma <luomat@capitalist.princeton.edu>
- #
- # DATE: 14 March 1996
- #
- # WARNING: USE ENTIRELY AT YOUR OWN RISK
- #
- # PURPOSE: easily mount floppy disks and CDs
- #
- # TESTED UNDER: NeXTStep 3.2 on my NeXTStation
- #
- #
- # USAGE NOTES: This script has two modes:
- #
- # LINE MODE: takes two arguments, one the type of disk, the other
- # is the disk label.
- # INTERACTIVE MODE: if there are not two arguments, then this script
- # will enter interactive mode
- #
- # NOTE: if the first argument is the word 'help' then a usage
- # summary is printed, and then the script exits.
- #
- # LINE MODE allows you to bypass the interactive questions, but it is
- # still required that you confirm the mounting action.
- #
- # NOTES:
- # I spent a lot of time on this, and my screw-ups caused more than
- # one 'fsck' on reboot, and at least 2 panics. This is not something
- # to just toy around with. However, I think this script helps take
- # some of the guesswork out. When in doubt, use the interactive
- # mode.
- #
- # The mount commands only work as 'root' I believe, so if this script is
- # not run as 'root' a warning pops up and asks if you still want to
- # continue.
- #
- # If the script goes to run a mount command, it prints the command
- # so you can see exactly what it is doing.
- #
- # KNOWN BUGS/Possible problems:
- # 1) Well, I don't consider this a bug, but if you
- # enter something which the program doesn't understand,
- # it exits. I try to tell you what caused it to
- # choke, where possible.
- #
- # 2) Sometimes the disk shows up in the Workspace and the 'Disk->Eject'
- # menu item remains greyed out. This does not follow any type of
- # pattern, as far as I could tell. Sometimes the same disk would work
- # once, and then it wouldn't work the next time.
- #
- # Workaround: umount by hand and then use 'disk -e'; or get my other
- # script called 'eject.sh' which will do this when run
- # as root.
- #
- # 3) FOR CDs: This was tested with two types of CDs: NeXT CDs and Non-NeXT
- # CDs. The difference is simple. If you have a NeXT CD mounted
- # properly, 'mount -p' shows the filesystem as '4.3'. A Non-NeXT
- # CD shows up as 'cfs'. Any other types will probably make this
- # script choke and die.
- #
- # 4) must run as root to use 'mount'
- #
- # 5) TESTED ONLY ON MY NeXTStation running 3.2
-
-
- name=`basename $0`
-
- ############################################################
- # DEFINE MOUNT DEVICES
- #
- # device for NeXT-formatted floppies
- nextflop=/dev/fd0a
-
- # device for DOS or Mac formatted floppies
- altflop=/dev/rfd0b
-
- # device for NeXT CDs
- nextcd=/dev/sd2a
-
- # device for NON-NeXT CD
- altcd=/dev/rsd2h
- ############################################################
-
- if [ "$1" = "help" ]
- then
-
- echo "Usage: $name disktype name"
- echo " where 'disktype' is ONE of these:"
- echo " mac-floppy dos-floppy next-floppy next-cd nonnext-cd "
- echo " and 'name' is the disk label"
- exit 0
-
- fi
-
- USER=`whoami`
-
- if [ "$USER" != "root" ]
- then
- echo "$name: only works when run as root."
- echo -n "Continue? [y/N] "
- stty cbreak
- continue=`dd if=/dev/tty bs=1 count=1 2>/dev/null`
- stty -cbreak
-
- if [ "$continue" != "y" ]
- then
- exit 0
- else
- echo " "
- fi
-
- fi
-
- if [ $# = "2" ] # if there are two arguments
- then
- disktype=$1 # floppy (mac/dos/next) or CD (next/nonnext)
- rawmount=$2 # /something
-
- else # if there are not two arguments
-
- echo -n "$name: CD or floppy disk? (PRESS: c or f) "
- stty cbreak
- disktype=`dd if=/dev/tty bs=1 count=1 2>/dev/null`
- stty -cbreak
- echo ""
-
- case $disktype in # check either for floppy disk or CD
- c) # if it is a CD
- echo -n "Is this a NeXT CD? [y/N] "
- stty cbreak
- cdtype=`dd if=/dev/tty bs=1 count=1 2>/dev/null`
- stty -cbreak
-
- case $cdtype in
- y|Y) disktype=next-cd
- ;;
- *) disktype=nonnext-cd
- ;;
- esac
- ;;
- f) # if it is a floppy disk
- echo -n "Is this a Mac, DOS, or NeXT floppy disk? (m|d|n) "
- stty cbreak
- floppytype=`dd if=/dev/tty bs=1 count=1 2>/dev/null`
- stty -cbreak
- case $floppytype in
- m|M) disktype=mac-floppy
- ;;
- d|D) disktype=dos-floppy
- ;;
- n|N) disktype=next-floppy
- ;;
- *) echo "$name: Unknown disktype, exiting."
- exit 0
- ;;
-
- esac
-
- ;;
- *) echo "$name: unknown disktype <$disktype>"
- exit 0
- ;;
- esac
-
- echo " "
- echo -n "$name: Where should it be mounted? "
- read rawmount
-
- fi
-
- # Ok, no matter how many arguments there are,
- # check what type of disk, what type of filesystem, and where
- # it should be mounted.
-
- # Big trouble here. There needs to be a '/' at the beginning
- # of the mount point. But is it good programming to depend
- # on the user to remember/know that? Probably not. But if
- # we assume they WON'T put a '/' and they do, well that causes
- # all sorts of hell. So we take the name the input, send it
- # through 'tr' and just strip away any '/' and put it in there
- # later. And we might as well strip away any spaces while
- # we are at it and replace them by '_'
- mtlocation=`echo $rawmount | tr -d "/" | tr -s ' ' '_'`
-
-
- echo "$name: About to try to mount a $disktype at /$mtlocation"
- echo -n " Is this correct? (Enter 'y' to continue) "
- read verify
-
- if [ "$verify" != "y" ]
- then
- echo "$name: Did not get confirmation, exiting."
- exit 0
- fi
-
- case $disktype in
- mac-floppy)
- echo "mount -t macintosh -o rw,removable $altflop /$mtlocation"
- mount -t macintosh -o rw,removable "$altflop" /"$mtlocation"
- ;;
-
- dos-floppy)
- echo "mount -t dos -o rw,removable $altflop /$mtlocation"
- mount -t dos -o rw,removable "$altflop" "/$mtlocation"
-
- ;;
-
- next-floppy)
- echo "mount -t 4.3 -o rw,removable $nextflop /$mtlocation"
- mount -t 4.3 -o rw,removable "$nextflop" /"$mtlocation"
-
- ;;
-
- next-cd)
- echo "mount -t 4.3 -o ro,removable $nextcd /$mtlocation"
- mount -t 4.3 -o ro,removable $nextcd /"$mtlocation"
- ;;
-
- nonnext-cd)
- echo "mount -t cfs -o ro,removable $altcd /$mtlocation"
- mount -t cfs -o ro,removable $altcd /"$mtlocation"
- ;;
-
- *) echo "$name: Unknown disktype <$disktype>, exiting."
- exit 0
- ;;
-
- esac
-
- exit 0
-
-